package com.lonely.web.controller.purchase;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lonely.common.core.domain.api.R;
import com.lonely.purchase.domain.dto.remainingmaterialinventory.*;
import com.lonely.purchase.domain.vo.remainingmaterialinventory.QueryRemainingMaterialInventoryPageVO;
import com.lonely.purchase.domain.vo.remainingmaterialinventory.QueryTypeInInventoryPageVO;
import com.lonely.purchase.domain.vo.remainingmaterialinventory.RemainingMaterialInventoryDetailVO;
import com.lonely.purchase.service.IRemainingMaterialInventoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author : 黄志标
 * @date: 2025/7/25 16:21
 * @description: 余料库存请求处理器
 */
@RestController
@RequestMapping("/purchaseManager/remainingMaterialInventory")
@Api(tags = "采购管理/余料库存")
public class RemainingMaterialInventoryController {

    @Autowired
    private IRemainingMaterialInventoryService remainingMaterialInventoryService;

    /**
     * 分页查询
     *
     * @param queryDto
     * @return
     */
    @PostMapping("/page")
    @ApiOperation(value = "物料采购分页查询")
    public R<Page<QueryRemainingMaterialInventoryPageVO>> page(@RequestBody @Validated QueryRemainingMaterialInventoryPageDTO queryDto) {
        return R.data(this.remainingMaterialInventoryService.page(queryDto));
    }


    /**
     * 批量删除
     *
     * @param batchRemoveDto
     * @return
     */
    @PostMapping("/batchRemove")
    @SaCheckPermission("purchase:remainingMaterialInventory:batchRemove")
    public R<Boolean> batchRemove(@RequestBody @Validated BatchRemoveRemainingMaterialInventoryDTO batchRemoveDto) {
        this.remainingMaterialInventoryService.batchRemove(batchRemoveDto);
        return R.status(true);
    }

    /**
     * 详情
     *
     * @param id
     * @return
     */
    @GetMapping("/detail/{id}")
    public R<RemainingMaterialInventoryDetailVO> detail(@PathVariable("id") Long id) {
        return R.data(this.remainingMaterialInventoryService.detail(id));
    }

    /**
     * 编辑余料库存
     *
     * @param submitDto
     * @return
     */
    @PostMapping("/submit")
    @SaCheckPermission("purchase:remainingMaterialInventory:submit")
    public R<Boolean> submit(@RequestBody @Validated RemainingMaterialInventorySubmitDTO submitDto) {
        this.remainingMaterialInventoryService.submit(submitDto);
        return R.status(true);
    }

    /**
     * 录入库存时物料库存分页列表
     *
     * @param pageDto
     * @return
     */
    @PostMapping("/queryTypeInMaterialInventoryPage")
    public R<Page<QueryTypeInInventoryPageVO>> queryTypeInMaterialInventoryPage(@RequestBody @Validated QueryTypeInMaterialInventoryPageDTO pageDto) {
        return R.data(this.remainingMaterialInventoryService.queryTypeInMaterialInventoryPage(pageDto));
    }

    /**
     * 录入库存
     *
     * @param typeInInventorys
     * @return
     */
    @PostMapping("/typeInRemainingMaterialInventory")
    @SaCheckPermission("purchase:remainingMaterialInventory:typeInRemainingMaterialInventory")
    public R<Boolean> typeInRemainingMaterialInventory(@RequestBody @Validated List<TypeInMaterialInventorySubmitDTO> typeInInventorys) {
        this.remainingMaterialInventoryService.typeInRemainingMaterialInventory(typeInInventorys);
        return R.status(true);
    }
}
